﻿using System;
using System.Web.Mvc;
using System.Web.Routing;
using Ninject;
using System.Linq;
using $myprojectname$.Domain.Abstract;
using $myprojectname$.Domain;
using System.Collections.Generic;
using $myprojectname$.Infrastructure.Abstract.Providers;
using $myprojectname$.Infrastructure.Providers;

namespace $myprojectname$.Infrastructure.IOC
{
/// <summary>
/// It allows controllers to be instantiated through the Ninject IOC container.
/// </summary>
public class NinjectControllerFactory : DefaultControllerFactory
{
    private IKernel ninjectKernel;
    public NinjectControllerFactory()
    {
        ninjectKernel = new StandardKernel();
        AddBindings();
    }

    protected override IController GetControllerInstance(RequestContext requestContext,
    Type controllerType)
    {
        return controllerType == null
        ? null
        : (IController)ninjectKernel.Get(controllerType);
    }

    private void AddBindings()
    {
       ninjectKernel.Bind<IProductRepository>().To<ProductRepository>();
       ninjectKernel.Bind<IAuthenticationProvider>().To<AuthenticationProvider>();
    }
}
}